//
//  MZServeViewController.m
//  minzuwenhuagong
//
//  Created by WANG CUNRUI on 14-5-23.
//  Copyright (c) 2014年 WANG CUNRUI. All rights reserved.
//

#import "MZServeViewController.h"
#import "QuartzCore/QuartzCore.h"
#import <UIKit/UITextInput.h>
#import "MZAppDelegate.h"


@interface MZServeViewController ()<JScrollViewViewDelegate,UIScrollViewDelegate,UIAlertViewDelegate>
@property (strong ,nonatomic) UILabel *label5;
@property (strong ,nonatomic) UIWebView *webView;
@end

@implementation MZServeViewController

@synthesize label1 = _label1;
@synthesize label1_1 = _label1_1;
@synthesize label2 = _label2;
@synthesize label3 = _label3;
@synthesize huancun = _huancun;
@synthesize guanyu = _guanyu;
@synthesize more = _more;
@synthesize scrollview = _scrollView;
@synthesize imageView =_imageView;
NSMutableArray *imageArray;



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)loadView
{
    [super loadView];
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    CGRect frame = self.view.bounds;
    CGSize f = frame.size;
    CGFloat h = f.height;
    CGFloat w = f.width;
    _scrollView =[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,w,h-115)];
    _scrollView.contentSize=CGSizeMake(320,915);
    _scrollView.backgroundColor=[UIColor colorWithRed:0.9373 green:0.9216 blue:0.9059 alpha:1.0];
    _scrollView.pagingEnabled=NO;
    
    NSMutableArray *viewArray = [[NSMutableArray alloc] init];
    for(int k=1; k<=5; k++)
    {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"m%d.png",k]]];
        [viewArray addObject:imageView];
    }
    _imageView = [[JScrollView_PageControl_AutoScroll alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
    _imageView.autoScrollDelayTime = 3.0;
    _imageView.delegate = self;
    [_imageView setViewsArray:viewArray];
    [_scrollView addSubview:_imageView];
    [_imageView shouldAutoShow:YES];
    
    _label5 = [[UILabel alloc] initWithFrame:CGRectMake( -10, 170, 340, 30)];
    _label5.layer.borderWidth = 1;
    _label5.layer.cornerRadius = 4;
    _label5.backgroundColor =  [UIColor colorWithRed:20/255.0 green:40/255.0 blue:40/255.0 alpha:0.3];
    _label1.layer.borderColor = [[UIColor clearColor] CGColor];
    [_scrollView addSubview:_label5];

    _label1 = [[UILabel alloc] initWithFrame:CGRectMake( 10, 220, 300, 170)];
    _label1.layer.borderWidth = 1;
    _label1.layer.borderColor = [[UIColor grayColor] CGColor];
    _label1.layer.cornerRadius = 4;
    [_scrollView addSubview:_label1];
    UIImageView *clockImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_clock.png"]];
    clockImage.frame = CGRectMake(10,5,15,15);
    [_label1 addSubview:clockImage];
    _label1_1= [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 200, 30)];
    _label1_1.font = [UIFont boldSystemFontOfSize:12];
    _label1_1.textColor = [UIColor blackColor];
    _label1_1.numberOfLines = 2;
    _label1_1.text = @"开放时间\n9:00-16:00 周六日无休";
    [_label1 setBackgroundColor:[UIColor clearColor]];
    [_label1_1 setBackgroundColor:[UIColor clearColor]];
    [_label1 addSubview:_label1_1];
    UIImageView *lineImage1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"black.jpg"]];
    lineImage1.frame = CGRectMake(0,30,300,0.5);
    [_label1 addSubview:lineImage1];
    UIImageView *adressImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"07-map-marker.png"]];
    adressImage.frame = CGRectMake(10,35,13,13);
    [_label1 addSubview:adressImage];
    UIImageView *subwayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ditie.png"]];
    subwayImage.frame = CGRectMake(8,72,20,20);
    [_label1 addSubview:subwayImage];
    _label1_2= [[UILabel alloc] initWithFrame:CGRectMake(30, 32, 200, 30)];
    _label1_2.font = [UIFont boldSystemFontOfSize:12];
    _label1_2.textColor = [UIColor blackColor];
    _label1_2.numberOfLines = 3;
    _label1_2.text = @"地址\n北京市西城区复兴门内大街49号";
    [_label1_2 setBackgroundColor:[UIColor clearColor]];
    [_label1 addSubview:_label1_2];
    _label1_3= [[UILabel alloc] initWithFrame:CGRectMake(30, 70, 200, 50)];
    _label1_3.font = [UIFont boldSystemFontOfSize:12];
    _label1_3.textColor = [UIColor blackColor];
    _label1_3.numberOfLines = 3;
    _label1_3.text = @"地铁\n乘坐南菜园-北京站东专线抵达西单\n路口东站后，向西150米，向北20米";
    [_label1_3 setBackgroundColor:[UIColor clearColor]];
    [_label1 addSubview:_label1_3];
    UIImageView *lineImage2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"black.jpg"]];
    lineImage2.frame = CGRectMake(0,70,300,0.5);
    [_label1 addSubview:lineImage2];
    UIImageView *lineImage3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"black.jpg"]];
    lineImage3.frame = CGRectMake(0,120,300,0.5);
    [_label1 addSubview:lineImage3];
    UIImageView *busImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bus.png"]];
    busImage.frame = CGRectMake(9,122,18,18);
    [_label1 addSubview:busImage];
    _label1_4= [[UILabel alloc] initWithFrame:CGRectMake(30, 122, 220, 50)];
    _label1_4.font = [UIFont boldSystemFontOfSize:12];
    _label1_4.textColor = [UIColor blackColor];
    _label1_4.numberOfLines = 3;
    _label1_4.text = @"公交\n10，15，626，7，205夜间车，抵达民\n族文化宫站后，向东90米，向北20米";
    [_label1_4 setBackgroundColor:[UIColor clearColor]];
    [_label1 addSubview:_label1_4];
   

    _label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 410, 300, 330)];
    _label2.font = [UIFont boldSystemFontOfSize:10];
    [_label2 setBackgroundColor:[UIColor clearColor]];
    _label2.layer.borderWidth = 1;
    _label2.layer.borderColor = [[UIColor grayColor] CGColor];
    _label2.layer.cornerRadius = 4;
    [_scrollView addSubview:_label2];
    UIImageView *phoneImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tel.png"]];
    phoneImage.frame = CGRectMake(10,5,15,15);
    [_label2 addSubview:phoneImage];
    _label2_1= [[UILabel alloc] initWithFrame:CGRectMake(30, 5, 180, 15)];
    _label2_1.font = [UIFont boldSystemFontOfSize:12];
    _label2_1.textColor = [UIColor blueColor];
    _label2_1.numberOfLines = 1;
    _label2_1.text = @"团体预约电话 （010）66024433";
    [_label2_1 setBackgroundColor:[UIColor clearColor]];
    UITapGestureRecognizer *tapGesture =
    [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openTEL:)];
    _label2_1.userInteractionEnabled = YES;
    _label2.userInteractionEnabled = YES;
    [_scrollView addGestureRecognizer:tapGesture];
    [_label2 addSubview:_label2_1];
    UIImageView *lineImage4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"black.jpg"]];
    lineImage4.frame = CGRectMake(0,24,300,0.5);
    [_label2 addSubview:lineImage4];
    UIImageView *bookImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"book.png"]];
    bookImage.frame = CGRectMake(10,30,18,18);
    [_label2 addSubview:bookImage];
    _label2_2= [[UILabel alloc] initWithFrame:CGRectMake(30, 25, 220, 300)];
    _label2_2.font = [UIFont boldSystemFontOfSize:12];
    _label2_2.textColor = [UIColor blackColor];
    _label2_2.numberOfLines = 20;
    _label2_2.text = @"参观须知\n1、酗酒、衣冠不整等影响公众形象者\n以及无行为能力或限制行为能力者无监\n护人陪伴的谢绝入馆参观。\n2、请自觉接受安检，严禁将违禁物品\n带入馆内，入馆前请将大件物品寄存，\n贵重物品自行保管。\n3、严禁携带宠物入馆。\n4、请自觉保持环境卫生，请您不要将\n十五、饮料带入展厅，请勿随地吐痰、\n乱扔杂物，严禁在馆内吸烟或使用明火。\n5、请自觉爱护公共设施，请勿触摸展\n厅内的文物、橱柜等设施。\n6、按照国际惯例展厅内请勿摄像，拍照\n请勿使用闪光灯及三脚架，所拍照片\n禁止用于商业和出版。\n7、请自觉遵守参观秩序，服从馆内工\n作人员现场引导，参观时请不要大声喧\n哗并建议您将手机设置为静音以免影响\n他人参观。";
    [_label2_2 setBackgroundColor:[UIColor clearColor]];
    [_label2 addSubview:_label2_2];
    
    
    _label3 = [[UILabel alloc] initWithFrame:CGRectMake(10, 760, 300, 20)];
    _label3.font = [UIFont boldSystemFontOfSize:10];
    [_label3 setBackgroundColor:[UIColor clearColor]];
    _label3.layer.borderWidth = 1;
    _label3.layer.borderColor = [[UIColor grayColor] CGColor];
    _label3.layer.cornerRadius = 4;
    UIImageView *netImage4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wangzhi.png"]];
    netImage4.frame = CGRectMake(5,3,15,15);
    [_label3 addSubview:netImage4];
    _label3_1= [[UILabel alloc] initWithFrame:CGRectMake(22, 3, 140, 15)];
    _label3_1.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
    _label3_1.font = [UIFont boldSystemFontOfSize:12];
    _label3_1.tag = 1;
    _label3_1.textColor = [UIColor blueColor];
    _label3_1.numberOfLines = 1;
    _label3_1.text = @"网址 http://www.cpon.cn";
    [_label3_1 setBackgroundColor:[UIColor clearColor]];
    UITapGestureRecognizer *tapGesture1 =
    [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openURL:)];
    _label3_1.userInteractionEnabled = YES;
    [_label3_1  addGestureRecognizer:tapGesture1];
    _label3.userInteractionEnabled = YES;
    [_label3 addSubview:_label3_1];
    [_scrollView addSubview:_label3];
    
    
    
    
    _huancun = [UIButton buttonWithType:UIButtonTypeCustom];
    _huancun.frame = CGRectMake(25, 810, 270, 30);
    _huancun.layer.cornerRadius = 4;
    [_huancun setTitle:@"清理缓存" forState:UIControlStateNormal];
    [_huancun setBackgroundColor:[UIColor colorWithRed:66/255.0 green:186/255.0 blue:21/255.0 alpha:1.0]];
    [_huancun addTarget:self action:@selector(butClick1:) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:_huancun];
    _guanyu = [UIButton buttonWithType:UIButtonTypeCustom];
    _guanyu.frame = CGRectMake(25, 860, 270, 30);
    _guanyu.layer.cornerRadius = 4;
    [_guanyu setTitle:@"关于" forState:UIControlStateNormal];
    [_guanyu setBackgroundColor:[UIColor colorWithRed:66/255.0 green:186/255.0 blue:21/255.0 alpha:1.0]];
    [_guanyu addTarget:self action:@selector(butClick2:) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:_guanyu];
    _more = [UIButton buttonWithType:UIButtonTypeCustom];
    _more.frame = CGRectMake(0, 0, 330, 200);
    _more.layer.cornerRadius = 4;
    [_more setBackgroundColor:[UIColor clearColor]];
    [_more addTarget:self action:@selector(butClick3:) forControlEvents:UIControlEventTouchUpInside];
    [_scrollView addSubview:_more];
    
    _scrollView.maximumZoomScale=2.0;
    _scrollView.minimumZoomScale=0.5;
    //    scrollview.decelerationRate=1;
    _scrollView.delegate=self;
    //canCancelContentTouches:YES-移动手指足够长度触发滚动事件,NO-scrollView发送 tracking events 后，就算用户移动手指，scrollView也不会滚动。
    _scrollView.canCancelContentTouches=NO;
    
    //当值是 YES的时候，用户触碰开始.要延迟一会，看看是否用户有意图滚动。假如滚动了，那么捕捉 touch-down事件，否则就不捕捉。假如值是NO，当用户触碰， scroll view会立即触发
    _scrollView.delaysContentTouches=YES;
    
    [self.view addSubview:_scrollView];
    
    self.view.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:240/255.0 alpha:1.0];
    
}

-(void)openURL:(id)sender
{
    NSString *url = nil;
    url = @"http://www.cpon.cn";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}

-(void)openTEL:(id)sender
{
//    NSString *tel = nil;
//    tel = @"tel://01066024433";
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tel]];
    if (_webView == nil) {
        _webView = [[UIWebView alloc] init];
    }
    NSLog(@"%p", _webView);
    NSURL *url = [NSURL URLWithString:@"tel://01066024433"];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [_webView loadRequest:request];
}



- (void)butClick2:(UIButton *)but
{
    _guanyuController = [[guanyuController alloc] init];
    [self.navigationController pushViewController:_guanyuController animated:YES];
    //[self makeAlertView];
}

- (void)butClick1:(UIButton *)but
{
    UIAlertView *result = [[UIAlertView alloc] initWithTitle:@"提示" message:@"是否清理缓存" delegate:self cancelButtonTitle:@"是"otherButtonTitles:@"否", nil];
    [result show];

    
}

- (void)butClick3:(UIButton *)but
{
    _moreViewController = [[MZmore2ViewController alloc] init];
    [self.navigationController pushViewController:_moreViewController animated:YES];
    //[self makeAlertView];
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
        if (buttonIndex == 0) {
        MZAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
        [appDelegate.myCache clearCachedResponsesForStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
        
    }

}



//- (void)drawTextInRect:(CGRect)rect {
//    //文字距离上下左右边框都有10单位的间隔
//    
//    CGRect newRect = CGRectMake(rect.origin.x + 10, rect.origin.y + 10, rect.size.width - 20, rect.size.height -20);
//    [super drawTextInRect:newRect];
//}

-(void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}




#pragma mark - Table view data source


@end